var statuses = {
    0: "All",
    1: "Private",
    2: "Shared"
}

var dbGroup = db.ConnectionStrings.findOne({}).DatabaseGroup
var collections = [ db.getSiblingDB("ClientPlatform").Portfolio, db.getSiblingDB("ClientPlatform").PortfolioMatches, db.getSiblingDB("ClientDW" + dbGroup).Portfolio ]
collections.forEach(function(collection){
    
    var bulk = collection.initializeUnorderedBulkOp();
    var myDocuments = collection.find({SharingStatus: { $type: 16 }}); 
    var ops = 0;     
    var startDate = new Date();
    myDocuments.forEach( 
        function(item){
            item.SharingStatus = statuses[item.SharingStatus];
            bulk.find({ _id: item._id }).replaceOne(item);
            
            if ((++ops %1000) === 0){
                bulk.execute();
                bulk = collection.initializeUnorderedBulkOp();
           }
        }
    )
                
    bulk.execute();   
    var endDate = new Date();
    print("\t\t\t" + collection + "\n\nStartDate: " + startDate + "\nEndDate: " + endDate + "\n\n")
})

